At 2:57 +0200 on 15/3/99, Silvio Emanuel Barbosa de Macedo wrote:
> When I insert data into a table with a sequence associated to a column
> (and the required trigger), how can I know the value the sequence has
> just generated ? (think in parallel accesses)
>
> Would this approach be the answer ?
> begin work
> insert...
> select max...
> commit
No, this approach is a waste of precious time... The correct approach is:
INSERT...
SELECT currval( 'seq_name' );
currval gives you the last value the sequence has given to the current
session. That is, it won't work if you use it before the insertion (because
the sequence didn't give you a number yet). It will also give you the
correct number even if between the INSERT and the SELECT, another process
or another connection also made an insert.
Herouth
--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma